#include <stdio.h>
#include <memory.h>

#define MAX_DICE    1000        /* max number of dice */
#define MAX_FACES   100         /* max number of faces on a die */

static int faces[MAX_DICE];     /* faces[i] = number of faces on die i */
static int count[MAX_FACES+1];  /* count[k] = number of dice with k faces */
static int start[MAX_FACES+1];  /* start[k] = first number on k-face dice */

int main()
{
    int num_dice;
    while (scanf("%d", &num_dice) == 1 && num_dice > 0)
    {
        int i, n, k, max_faces = 0;
        int avg_x2 = 0;

        /* Input number of faces on each die. */
        memset(count, 0, sizeof(count));
        for (i = 0; i < num_dice; i++)
        {
            int a;
            scanf("%d", &a);
            faces[i] = a;
            count[a]++;
            if (a > max_faces)
                max_faces = a;
        }

        /* Arrange the numbers. */
        n = 0;
        for (k = max_faces; k >= 1; k--)
        {
            if (count[k])
            {
                start[k] = n + 1;
                avg_x2 += ((n+1)+(n+k*count[k]))*count[k];
                n += k * count[k];
            }
        }

        /* Print result. */
        printf("%.5lf\n", (double)avg_x2 / 2.0);
        for (i = 0; i < num_dice; i++)
        {
            int j;
            k = faces[i];
            n = start[k];
            start[k] += k;

            printf("%d", n);
            for (j = n + 1; j <= n + k - 1; j++)
                printf(" %d", j);
            printf("\n");
        }
    }
    return 0;
}
